# -*- coding: utf-8 -*-
"""
@Time: 2021/5/29 11:25
@Author: 鹄望潇湘
@File: main.py.py
@desc: 
"""

import xlrd


def read_old_data(data_path: str) -> dict:
    result = {}
    file = xlrd.open_workbook(data_path, encoding_override="gbk")
    data = file.sheet_by_index(0)
    rows = data.nrows
    for i in range(1, rows):
        temp = data.cell(i, 2).value
        if temp in result.keys():
            print("警告："+temp+"已经存在，该值将被覆盖")
        result[temp] = data.cell(i, 3).value

    print("读取了"+str(len(result))+"条数据")
    return result


def read_now_data(data_path: str) -> dict:
    result = {}
    file = xlrd.open_workbook(data_path, encoding_override="gbk")
    data = file.sheet_by_index(0)
    rows = data.nrows
    for i in range(1, rows):
        temp = data.cell(i, 0).value
        if temp in result.keys():
            print("警告：" + temp + "已经存在，该值将被覆盖")
        result[temp] = data.cell(i, 1).value

    print("读取了" + str(len(result)) + "条数据")
    return result


def compare(data1: dict, data2: dict) -> dict:
    """

    :param data1:
    :param data2:
    :return: 在data1中而不在data2中的数据
    """
    result = dict()
    data1_key = data1.keys()
    data2_key = data2.keys()
    for item in data1_key:
        if item not in data2_key:
            result[item] = data1[item]
    return result


def print_dict(data: dict):
    for item in data.keys():
        print(item + "\t" + data[item])

if __name__=='__main__':
    wang_path = "./在校生数据-汪.xls"
    now_path = "./研究生系统在校生.XLS"
    wang_data = read_old_data(wang_path)
    now_data = read_now_data(now_path)

    print("在系统中而不在比对目标中：")
    result1 = compare(now_data, wang_data)
    print_dict(result1)

    print("在比对目标中而不在系统中：")
    result2 = compare(wang_data, now_data)
    print_dict(result2)

    pass

